﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QLKCB.Model;
using QLKCB.Common;

namespace QLKCB.Controller
{
    class cDangKyKhamBenh
    {

        ConnectDB connectDB = new ConnectDB();
        Utils utils = new Utils();

        public DataTable getLoaiKham()
        {
            String sql = "select * from LoaiKham";
            object[] param = { };
            DataTable dtLoaiKham = connectDB.ExeQuery(sql, param);
            return dtLoaiKham;
        }

        public string getMaKhamBenh()
        {
            string prefixKey = "KB";
            DateTime today = DateTime.Today;
            String nowDate = today.ToString("yyyyMMdd");
            string sql = "select top 1 MaPhieuDKKB from PhieuDKKB where MaPhieuDKKB like @maphieu + '%' order by MaPhieuDKKB desc";
            object[] param = { "@maphieu", prefixKey + nowDate };
            string key = utils.genKey(sql, param, 2, prefixKey);

            return key;
        }

        public int insertPhieuKhamBenh(string maPT, string maBN, string maLoaiKham, DateTime ngayLap, string chuanDoan)
        {

            string maKB = getMaKhamBenh();
            string sql = "insert into PhieuDKKB values (@maphieukb, @maphieuthu, @mabenhnhan, @maloaikham, @ngaylap, @chuandoan)";
            object[] param = { "@maphieukb", maKB, "@maphieuthu", maPT, "@mabenhnhan", maBN, "@maloaikham", maLoaiKham, "@ngaylap", ngayLap, "@chuandoan", chuanDoan };

            int result = connectDB.ExeNonQuery(sql, param);
            return result;

        }

    }
}
